package logic

import (
	"common"
	"common/zapx"
	"go.uber.org/zap"
	"models/dal/query"
	"swiper/internal/pb"
	"time"
)

// GetSwiperList 获取轮播图
func GetSwiperList(status *uint32) (ret []*pb.SwiperEntity) {
	ret = []*pb.SwiperEntity{}
	ctx, cancel := common.WithTimeoutContext(time.Second * 2)
	defer cancel()
	swiperModel := query.Q.FaSwiper.WithContext(ctx)

	if status != nil {
		swiperModel = swiperModel.Where(query.Q.FaSwiper.Status.Eq(int32(*status)))
	}

	list, err := swiperModel.Find()

	if err != nil {
		zapx.Logger.Error("[GetSwiperList]查询数据失败", zap.Error(err))
		return
	}
	for _, swiper := range list {
		ret = append(ret, &pb.SwiperEntity{
			Id:    swiper.ID,
			Thumb: common.ParseUri(swiper.Thumb),
		})
	}
	return
}
